home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / gcc / objam01.lha / objam / runtime / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-13  |  2.6 KB  |  146 lines

  1. /*
  2. ** ObjectiveAmiga: Misc functions
  3. ** See GNU:lib/libobjam/ReadMe for details
  4. */
  5.  
  6.  
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <exec/exec.h>
  10. #include <dos/dos.h>
  11. #include <clib/alib_protos.h>
  12. #include <proto/exec.h>
  13. #include <proto/dos.h>
  14. #include <stddef.h>
  15.  
  16. #include <clib/objc_protos.h>
  17.  
  18. #include <sys/cdefs.h>
  19. #include <inline/stubs.h>
  20.  
  21. #include "misc.h"
  22.  
  23. #include "objclib.h" /* For the global data */
  24. #include "zone.h" /* For quick access to the default zone */
  25.  
  26.  
  27. void __objc_sprintf (const char *buf, const char *format, ...)
  28. {
  29.   RawDoFmt((char *)format, &format+1, (void (*))"\x16\xC0\x4E\x75", (char *)buf);
  30. }
  31.  
  32.  
  33. void __printf_callback()
  34. {
  35.   register BPTR output asm("a3");
  36.   register LONG data asm("d0");
  37.  
  38.   FPutC(output,data);
  39. }
  40.  
  41.  
  42. void __objc_printf (const char *format, ...)
  43. {
  44.   RawDoFmt((char *)format, &format+1, __printf_callback, (APTR)Output());
  45. }
  46.  
  47.  
  48. int __objc_strcmp (const char *a, const char *b)
  49. {
  50.   int i=0;
  51.  
  52.   while(a[i]&&b[i])
  53.   {
  54.     if(a[i]<b[i]) return -1;
  55.     else if(b[i]<a[i]) return 1;
  56.     i++;
  57.   }
  58.  
  59.   if(a[i]) return 1;
  60.   else if(b[i]) return -1;
  61.   else return 0;
  62. }
  63.  
  64.  
  65. char *__objc_strcpy (char *to, const char *from)
  66. {
  67.   int i=0;
  68.  
  69.   for(;;)
  70.   {
  71.     to[i]=from[i];
  72.     if(!from[i]) break;
  73.     i++;
  74.   }
  75.  
  76.   return to;
  77. }
  78.  
  79.  
  80. void __objc_NewList (struct List *list)
  81. {
  82.   list->lh_Head=(struct Node *)(&(list->lh_Tail));
  83.   list->lh_Tail=0;
  84.   list->lh_TailPred=(struct Node *)(&(list->lh_Head));
  85. }
  86.  
  87.  
  88. void __objc_abort(void)
  89. {
  90.   register void *globaldata asm("a4");
  91.   globaldata=libinitdata->globaldata;
  92.   (*(libinitdata->abort))();
  93. }
  94.  
  95.  
  96. /******************************* misc functions */
  97.  
  98. static const char * __objc_nomem_str="Virtual memory exhausted";
  99.  
  100. void objc_fatal(const char* msg)
  101. {
  102.   printf("*** Objective C runtime error:\n  %s.\n  Aborting.\n",msg);
  103.   abort();
  104. }
  105.  
  106. void __objc_archiving_fatal(const char* format, int arg1)
  107. {
  108.   printf("*** Objective C archiving error:\n  ");
  109.   printf(format,arg1);
  110.   printf(".\n  Aborting.\n");
  111.   abort();
  112. }
  113.  
  114. void * __objc_xmalloc(int size)
  115. {
  116.   void *res;
  117.   if(!(res=NXZoneMalloc(__DefaultMallocZone,(int)size))) objc_fatal(__objc_nomem_str);
  118.   return res;
  119. }
  120.  
  121. void * __objc_xmalloc_from_zone(int size, NXZone* zone)
  122. {
  123.   void *res;
  124.   if(!(res=NXZoneMalloc(zone,(int)size))) objc_fatal(__objc_nomem_str);
  125.   return res;
  126. }
  127.  
  128. void * __objc_xrealloc(void* mem, int size)
  129. {
  130.   void *res;
  131.   if(!(res=NXZoneRealloc(__DefaultMallocZone,mem,(int)size))) objc_fatal(__objc_nomem_str);
  132.   return res;
  133. }
  134.  
  135. void * __objc_xcalloc(int nelem, int size)
  136. {
  137.   void *res;
  138.   if(!(res=NXZoneCalloc(__DefaultMallocZone,(int)nelem,(int)size))) objc_fatal(__objc_nomem_str);
  139.   return res;
  140. }
  141.  
  142. void __objc_xfree(void *mem)
  143. {
  144.   NXZoneFree(NXZoneFromPtr(mem),mem);
  145. }
  146.